<?php
namespace app\serverfund\service\recharge;

use \app\manage\service\ApiBase;
/**
 * @author:      李颖
 * @DateTime:    2017-09-09 16:41:06
 * @Description: 充值
 */
class Recharge extends ApiBase
{


	protected $rechargeValidate = '\app\serverfund\validate\Recharge';
    protected $rechargeLogic = '\app\serverfund\logic\Recharge';

    /*充值时获取二维码*/
    public function recharge(): array 
    {
        $data = $this->haveIssetReceiveData(['user_id'=>0, 'app_id'=>0, 'token'=>' ','pay_type'=>' ','recharge_type'=>' ', 'create_ip'=>' ', 'recharge_currency'=>0, 'money'=>0, 'desc'=>' ', 'attach'=>' ', 'phone_no'=>'', 'customer_name'=>'', 'cerd_id'=>'', 'card_no'=>'', 'cvn2'=>'', 'valid_date'=>'']);
        if($data['recharge_type'] == 'currency' && !$data['recharge_currency']){
            return verify_err(null, '充值亚数币不可无值');
        }
        return $this->stepRun($data, 'recharge', '', $this->rechargeValidate, $this->rechargeLogic);
    }

    /*查询是否充值成功*/
    public function isRecharge(): array 
    {
    	$data = $this->haveIssetReceiveData(['id'=>0]);
    	return $this->stepRun($data, 'isRecharge', '', $this->rechargeValidate, $this->rechargeLogic);
    }

    //支付订单时获取二维码  支付订单获取二维码之前要进行检验传入的支付订单的信息数据,即支付信息正确的
    public function getPayCode(): array 
    {
        //接收参数：  获取二维码参数 + 支付订单时的参数
        $data = $this->haveIssetReceiveData(['user_id'=>0, 'app_id'=>0, 'token'=>' ', 'create_ip'=>' ', 'desc'=>' ', 'attach'=>' ', 'id'=>0, 'integral_deduction'=>0, 'integral_deduction_fund'=>0, 'total_price'=>0, 'final_total_price'=>0, 'fund_type'=>' ', 'is_use_integral'=>' ', 'action'=>'pay_order'], []);

        $data['pay_type'] = $data['fund_type'];
        $data['recharge_type'] = 'cash';
        $data['money'] = $data['final_total_price'];
        return $this->stepRun($data, 'getPayCode', '', $this->rechargeValidate, $this->rechargeLogic);
    }

    //支付订单时，使用杉奇无卡支付
    //版本2 给action添加一个类型 pay_certificate
    public function sqPayOrder(): array 
    {
        //接收参数：  获取二维码参数 + 支付订单时的参数
        $data = $this->haveIssetReceiveData(['user_id'=>0, 'app_id'=>0, 'token'=>' ', 'create_ip'=>' ', 'desc'=>' ', 'phone_no'=>' ', 'customer_name'=>' ', 'cerd_id'=>' ', 'card_no'=>' ', 'cvn2'=>' ', 'valid_date'=>' ', 'id'=>0, 'integral_deduction'=>0, 'integral_deduction_fund'=>0, 'total_price'=>0, 'final_total_price'=>0, 'is_use_integral'=>' ', 'action'=>'pay_order'], []);

        $data['pay_type'] = $data['fund_type'] = 'unionpay';  //使用银行卡支付
        $data['recharge_type'] = 'cash';
        $data['money'] = $data['final_total_price'];
        return $this->stepRun($data, 'sqPayOrder', '', $this->rechargeValidate, $this->rechargeLogic);
    }

    //根据id获取该支付记录  第三方支付订单开始
    public function getPayInfo(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0]);
        return $this->stepRun($data, 'getPayInfo');
    }

    /*根据id修改该支付记录 第三方支付订单结束*/
    public function updatePayLog(): array 
    {
        $data = $this->haveIssetReceiveData(['id'=>0, 'steps_operate_result'=>[], 'operate_result'=>' ']);
        return $this->stepRun($data, 'updatePayLog');
    }

    

    
}